package com.yehongyu.mytools.poidoc;

import java.io.FileInputStream;
import java.io.IOException;

import org.apache.log4j.Logger;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.util.PDFTextStripper;

public class PdfUtil {
	
	private static final Logger logger = Logger.getLogger(PdfUtil.class);

	/**
	 * 读取PDF内容
	 * @param path
	 * @return 文本
	 */
	public static String readPdf(String path){
		PDFParser p;
		String content = null;
		try {
			p = new PDFParser(new FileInputStream(path));
			p.parse();
			PDFTextStripper t = new PDFTextStripper();
			content = t.getText(p.getPDDocument());
		} catch (IOException e) {
			logger.error("exception io error!",e);
		}
		return content;
	}
	
	public static void main(String[] args){
		System.out.println(PdfUtil.readPdf("\\\\YingYang\\software\\aliba.pdf"));
	}

}
